<% layout('/layout/default.html', {title: '伊利员工信息详情', libs: ['validate', 'icheck']}){ %>
<div class="main-content">
		<div class="card-header">
			<i class="fas fa-pencil-alt"></i> ${yiliEmployee.isNewRecord?'新增伊利员工信息':'编辑伊利员工信息'}
		</div>
		<#form:form id="inputForm" model="${yiliEmployee}"  class="form-horizontal" action="${ctx}/yili/yiliEmployee/save" method="post" >
			<div class="card-body">
				<#form:hidden path="id"/>
				<div class="row">
					<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
						<div class="form-group row">
							<label class="col-form-label col-lg-4 col-md-4 text-right" title="">
								<span style="color:red;">*</span> 员工姓名：
							</label>
							<div class="col-lg-8 col-md-8">
								<#form:input path="name"  maxlength="64" class="form-control form-control-sm required "/>
							</div>
						</div>
					</div>
					<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
						<div class="form-group row">
							<label class="col-form-label col-lg-4 col-md-4 text-right" title="">
								<span style="color:red;">*</span> 性别：
							</label>
							<div class="col-lg-8 col-md-8">
								<#form:select path="gender" name="label" data="getDictList:sex" class="form-control form-control-sm select2 required" />
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
						<div class="form-group row">
							<label class="col-form-label col-lg-4 col-md-4 text-right" title="">
								<span style="color:red;">*</span> 出生日期：
							</label>
							<div class="col-lg-8 col-md-8">
								<input id="birthday" type="text" name="birthday" maxlength="20" readonly="readonly" class="form-control form-control-sm  required"
										value="${yiliEmployee.birthday}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});" onchange="birthdayChange()"/>
							</div>
						</div>
					</div>
					<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
						<div class="form-group row">
							<label class="col-form-label col-lg-4 col-md-4 text-right" title="">
								<span style="color:red;">*</span> 年龄：
							</label>
							<div class="col-lg-8 col-md-8">
								<#form:input path="age"  maxlength="11" class="form-control form-control-sm  readonly required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
						<div class="form-group row">
							<label class="col-form-label col-lg-4 col-md-4 text-right" title="">
								<span style="color:red;">*</span> 手机号：
							</label>
							<div class="col-lg-8 col-md-8">
								<#form:input path="mobile"  maxlength="32" class="form-control form-control-sm phone required  "/>
							</div>
						</div>
					</div>
					<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
						<div class="form-group row">
							<label class="col-form-label col-lg-4 col-md-4 text-right" title="">
								所属部门：
							</label>
							<div class="col-lg-8 col-md-8">
								<#form:treeselect id="officeId" name="office.id" value="${yiliEmployee.office.id!}" labelName="office.name"
								labelValue="${yiliEmployee.office.name!}" title="部门" url="/sys/office/treeData?type=2" cssClass="form-control-sm " notAllowSelectParent="true" />
							</div>
						</div>
					</div>
				</div>

<!--				<div class="control-group">-->
<!--					<div class="table-title">社保信息：</div>-->
<!--					<div class="controls">-->
<!--						<table id="contentTable" class="table table-head-fixed table-bordered table-hover" cellspacing="0" width="100%">-->
<!--							<thead>-->
<!--								<tr>-->
<!--									<th class="hide"></th>-->
<!--									<th>社保类型</th>-->
<!--									<th>缴费期间</th>-->
<!--									<th>个人缴费金额</th>-->
<!--									<% if(hasPermi('yili:yiliEmployee:edit')){ %>-->
<!--										<th width="10"> </th>-->
<!--									<%}%>-->
<!--								</tr>-->
<!--							</thead>-->
<!--							<tbody id="yiliSocialSecurityInfoList">-->
<!--							</tbody>-->
<!--							<% if(hasPermi('yili:yiliEmployee:edit')){ %>-->
<!--								<tfoot>-->
<!--									<tr><td colspan="6"><a href="javascript:" onclick="addRow('#yiliSocialSecurityInfoList', yiliSocialSecurityInfoRowIdx, yiliSocialSecurityInfoTpl);yiliSocialSecurityInfoRowIdx = yiliSocialSecurityInfoRowIdx + 1;" class="btn btn-sm btn-default"><i class="fa fa-plus"></i> 新增</a></td></tr>-->
<!--								</tfoot>-->
<!--							<%}%>-->
<!--						</table>-->
<!--					</div>-->
<!--				</div>-->
			</div>

			<div class="box-footer">
				<div class="row">
					<div class="offset-md-2 col-md-10">
						<% if (hasPermi('yili:yiliEmployee:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> 保 存</button>
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="window.parent.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> 关 闭</button>
					</div>
				</div>
			</div>
		</#form:form>
</div>
<% } %>

<script type="text/javascript">
	$("#inputForm").validate({
		submitHandler: function(form){
			js.ajaxSubmitForm($(form), function(data){
				js.showMessage(data.message);
				if(data.result == 'true'){
					window.parent.closeCurrentTabPage(window.parent.refreshTab);
				}
			});
	    }
	});

	// function addRow(list, idx, tpl, row){
	// 	$(list).append(Mustache.render(tpl, {
	// 		idx: idx, delBtn: true, row: row
	// 	}));
	// 	$(list+idx).find("select").each(function(){
	// 		$(this).val($(this).attr("data-value"));
	// 	});
	// 	$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
	// 		var ss = $(this).attr("data-value").split(',');
	// 		for (var i=0; i<ss.length; i++){
	// 			if($(this).val() == ss[i]){
	// 				$(this).attr("checked","checked");
	// 			}
	// 		}
	// 	});
	// }
	//
	// function delRow(obj, prefix){
	// 	var id = $(prefix+"_id");
	// 	var delFlag = $(prefix+"_delFlag");
	// 	if (id.val() == ""){
	// 		$(obj).parent().parent().remove();
	// 	}else if(delFlag.val() == "0"){
	// 		delFlag.val("1");
	// 		$(obj).html("&divide;").attr("title", "撤销删除");
	// 		$(obj).parent().parent().addClass("error");
	// 	}else if(delFlag.val() == "1"){
	// 		delFlag.val("0");
	// 		$(obj).html("&times;").attr("title", "删除");
	// 		$(obj).parent().parent().removeClass("error");
	// 	}
	// }

	function birthdayChange() {
		js.print("aaaaaaaaaaaaaaaaaaaaaaa");
		var birthday = $("#birthday").val();
		var age = getAge(birthday);

		if (age == -1) {
			js.showErrorMessage('出生日期晚于今天，数据有误');
		} else if (age == -2) {
			js.showErrorMessage('输入的日期格式错误');
		} else {
			$("#age").val(age);
		}
	}

	function getAge(strAge) {
		var birArr = strAge.split("-");
		var birYear = birArr[0];
		var birMonth = birArr[1];
		var birDay = birArr[2];

		d = new Date();
		var nowYear = d.getFullYear();
		var nowMonth = d.getMonth() + 1; //记得加1
		var nowDay = d.getDate();
		var returnAge;

		if (birArr == null) {
			return false
		};
		var d = new Date(birYear, birMonth - 1, birDay);
		if (d.getFullYear() == birYear && (d.getMonth() + 1) == birMonth && d.getDate() == birDay) {
			if (nowYear == birYear) {
				returnAge = 0; //
			} else {
				var ageDiff = nowYear - birYear; //
				if (ageDiff > 0) {
					if (nowMonth == birMonth) {
						var dayDiff = nowDay - birDay; //
						if (dayDiff < 0) {
							returnAge = ageDiff - 1;
						} else {
							returnAge = ageDiff;
						}
					} else {
						var monthDiff = nowMonth - birMonth; //
						if (monthDiff < 0) {
							returnAge = ageDiff - 1;
						} else {
							returnAge = ageDiff;
						}
					}
				} else {
					return  -1; //返回-1 表示出生日期输入错误 晚于今天
				}
			}
			return returnAge;
		} else {
			return -2;
		}
	}
</script>

<script type="text/template" id="yiliSocialSecurityInfoTpl">//<!--
	<tr id="yiliSocialSecurityInfoList{{idx}}">
		<td class="hide">
			<input id="yiliSocialSecurityInfoList{{idx}}_id" name="yiliSocialSecurityInfoList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
			<input id="yiliSocialSecurityInfoList{{idx}}_delFlag" name="yiliSocialSecurityInfoList[{{idx}}].delFlag" type="hidden" value="0"/>
		</td>
		<td>
			<% var dictList = @DictUtils.getDictList('social_security_type'); %>
			<select id="yiliSocialSecurityInfoList{{idx}}_type" name="yiliSocialSecurityInfoList[{{idx}}].type" data-value="{{row.type}}" class="form-control form-control-sm required ">
				<option value=""></option>
				<% for(dict in dictList) { %>
					<option value="${dict.value}">${dict.label}</option>
				<% } %>
			</select>
		</td>
		<td>
			<input id="yiliSocialSecurityInfoList{{idx}}_paymentPeriod" name="yiliSocialSecurityInfoList[{{idx}}].paymentPeriod" type="text" readonly="readonly" maxlength="20" class="form-control form-control-sm required "
				value="{{row.paymentPeriod}}" onclick="WdatePicker({dateFmt:'yyyy-MM', isShowToday: false, isShowClear:false});"/>
		</td>
		<td>
			<input id="yiliSocialSecurityInfoList{{idx}}_paymentAmount" name="yiliSocialSecurityInfoList[{{idx}}].paymentAmount" type="text" value="{{row.paymentAmount}}" class="form-control form-control-sm number required"/>
		</td>
		<% if(hasPermi('yili:yiliEmployee:edit')){ %>
			<td class="text-center" width="10">
				{{#delBtn}}<span class="close" onclick="delRow(this, '#yiliSocialSecurityInfoList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
			</td>
		<%}%>
	</tr>//-->
</script>

<!--<script type="text/javascript">-->
<!--	var yiliSocialSecurityInfoRowIdx = 0, yiliSocialSecurityInfoTpl = $("#yiliSocialSecurityInfoTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");-->
<!--	$(document).ready(function() {-->
<!--		<% var yiliSocialSecurityInfoData = @JsonMapper.toJsonString(yiliEmployee.yiliSocialSecurityInfoList); %>-->
<!--		var list = ${yiliSocialSecurityInfoData};-->
<!--		for (var i=0; i<list.length; i++){-->
<!--			addRow('#yiliSocialSecurityInfoList', yiliSocialSecurityInfoRowIdx, yiliSocialSecurityInfoTpl, list[i]);-->
<!--			yiliSocialSecurityInfoRowIdx = yiliSocialSecurityInfoRowIdx + 1;-->
<!--		}-->
<!--	});-->
<!--</script>-->

